package com.gy.assistant.entity;

import android.os.Build;

import androidx.annotation.RequiresApi;

import java.util.ArrayList;

import im.zego.zim.entity.ZIMMessage;
import im.zego.zim.entity.ZIMMessageReaction;
import im.zego.zim.enums.ZIMMessageReceiptStatus;
import com.gy.assistant.enums.ChatItemType;

public class MessageInfo {
    private ChatItemType type;
    private String userName;
    private String header;
    private ZIMMessage message;
    private ZIMMessageReceiptStatus zimMessageReceiptStatus;
    private int receiptUnreadMemberCount;

    private final ArrayList<ZIMMessageReaction> reactions = new ArrayList<>();

    public void setType(ChatItemType type) {
        this.type = type;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setHeader(String header) {
        this.header = header;
    }

    public String getUserName() {
        return userName;
    }

    public ChatItemType getType() {
        return type;
    }

    public String getHeader() {
        return header;
    }

    public void setZIMMessage(ZIMMessage message) {
        this.message = message;
        zimMessageReceiptStatus = message.getReceiptStatus();
        reactions.clear();
        reactions.addAll(message.getReactions());
    }

    public ZIMMessage getZIMMessage() {
        return message;
    }

    public ZIMMessageReceiptStatus getZimMessageReceiptStatus() {
        return zimMessageReceiptStatus;
    }

    public void setZimMessageReceiptStatus(ZIMMessageReceiptStatus zimMessageReceiptStatus) {
        this.zimMessageReceiptStatus = zimMessageReceiptStatus;
    }

    public ArrayList<ZIMMessageReaction> getMessageReactions() { return reactions; }

    @RequiresApi(api = Build.VERSION_CODES.N)
    public void updateZIMMessageReaction(ZIMMessageReaction reaction) {
        reactions.removeIf(
                reaction1 -> reaction1.reactionType.equals(reaction.reactionType));
        if (reaction.isSelfIncluded || !reaction.userList.isEmpty()) {
            reactions.add(reaction);
        }
    }

    public void setReceiptUnreadMemberCount(int unreadMemberCount){
        receiptUnreadMemberCount = unreadMemberCount;
    }

    public int getReceiptUnreadMemberCount() {
        return receiptUnreadMemberCount;
    }
}
